package com.jyw.router.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.jyw.router.common.annotation.Anonymous;
import com.jyw.router.common.core.domain.CommonResult;
import com.jyw.router.hospital.domain.vo.RegisterUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jyw.router.common.annotation.Log;
import com.jyw.router.common.core.controller.BaseController;
import com.jyw.router.common.core.domain.AjaxResult;
import com.jyw.router.common.enums.BusinessType;
import com.jyw.router.hospital.domain.HospitalRegisterUser;
import com.jyw.router.hospital.service.IHospitalRegisterUserService;
import com.jyw.router.common.utils.poi.ExcelUtil;
import com.jyw.router.common.core.page.TableDataInfo;

/**
 * 注册用户信息Controller
 * 
 * @author shenjun
 * @date 2023-04-17
 */
@RestController
@RequestMapping("/hospital/hospitalUser")
@Api(tags = "医院注册用户API")
public class HospitalRegisterUserController extends BaseController
{
    @Autowired
    private IHospitalRegisterUserService hospitalRegisterUserService;

    /**
     * 查询注册用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalRegisterUser hospitalRegisterUser)
    {
        startPage();
        List<HospitalRegisterUser> list = hospitalRegisterUserService.selectHospitalRegisterUserList(hospitalRegisterUser);
        return getDataTable(list);
    }

    /**
     * 导出注册用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUser:export')")
    @Log(title = "注册用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalRegisterUser hospitalRegisterUser)
    {
        List<HospitalRegisterUser> list = hospitalRegisterUserService.selectHospitalRegisterUserList(hospitalRegisterUser);
        ExcelUtil<HospitalRegisterUser> util = new ExcelUtil<HospitalRegisterUser>(HospitalRegisterUser.class);
        util.exportExcel(response, list, "注册用户信息数据");
    }

    /**
     * 获取注册用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hospitalRegisterUserService.selectHospitalRegisterUserById(id));
    }

    /**
     * 新增注册用户信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUser:add')")
    @Log(title = "注册用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalRegisterUser hospitalRegisterUser)
    {
        return toAjax(hospitalRegisterUserService.insertHospitalRegisterUser(hospitalRegisterUser));
    }

    /**
     * 修改注册用户信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUser:edit')")
    @Log(title = "注册用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalRegisterUser hospitalRegisterUser)
    {
        return toAjax(hospitalRegisterUserService.updateHospitalRegisterUser(hospitalRegisterUser));
    }

    /**
     * 删除注册用户信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUser:remove')")
    @Log(title = "注册用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hospitalRegisterUserService.deleteHospitalRegisterUserByIds(ids));
    }

    /**
     * 禁用注册用户
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUser:disabled')")
    @Log(title = "禁用注册用户", businessType = BusinessType.DISABLED)
    @PutMapping("/disabled")
    public CommonResult disabled(Long id)
    {
        hospitalRegisterUserService.disabled(id);
        return CommonResult.success();
    }


    /**
     * 禁用注册用户
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUser:enable')")
    @Log(title = "启用注册用户", businessType = BusinessType.ENABLE)
    @PutMapping("/enable")
    public CommonResult enable(Long id)
    {
        hospitalRegisterUserService.enable(id);
        return CommonResult.success();
    }

    @Anonymous
    @Log(title = "注册用户",businessType = BusinessType.INSERT)
    @PostMapping("register")
    @ApiOperation("注册用户")
    public CommonResult register(@RequestBody @Valid RegisterUserVo registerUser){
        hospitalRegisterUserService.registerUser(registerUser);
        return CommonResult.success();
    }
}
